

; SERVER

(defun start-communication ()
  (comm:start-up-server 
   :function (lambda (port)
               (debug-print "connection requested" port)
               (let ((stream (make-instance 'comm:socket-stream :socket port
                                            :direction :io :element-type 'base-char)))
;                 (read-message-from-stream communicator stream)))
                 (mp:process-run-function (format nil "communication-server-~D" port)
                  '()
                  'read-message-from-stream stream)))
   :service *device-port*))

(defun read-message-from-stream (stream)
  (debug-print "reading message from" stream)
  (unwind-protect
       (let* ((message (read stream)))
             ;(actor (remote-object-actor (message-receiver message))))
         (debug-print "receiving message" (function-call-name (message-function-call message)))
         (debug-print "receiver" (message-receiver message))
         ;(receive-message actor message)
         (close stream))
  (close stream)))

;(start-communication)

; CLIENT

(defun transmit-msg (message)
  (let ((*package* (find-package 'closer-common-lisp-user))
        (*print-circle* t))
    (debug-print "opening stream to" "progpc30.vub.ac.be.")
    (debug-print "with port" *device-port*)
    (with-open-stream (stream (comm:open-tcp-stream "progpc30.vub.ac.be." *device-port*))
      (debug-print "sending message" (function-call-name (message-function-call message)))
      (write message :stream stream :escape t :readably t)
      (force-output stream))))

;(transmit-msg (make-message :sender "Bob" :receiver "Alice" :function-call (make-function-call :name "foo" :arguments "bar") :future nil))